/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.staff;

import static model.Constants.NULL_ARGUMENT_MESSAGE;
import model.personInfo.Contacts;
import model.personInfo.Name;
import model.personInfo.Origin;
/**
 * Contains information about person.
 * @author Dmitri Paziy
 */
public abstract class Person {
    private final Name name;
    private final Origin origin;
    private final Contacts contacts;

    /**
     * @param name Instance of Name, that contains information about person's name
     * @param origin Instance of Origin, that contains information about person's origin
     * @param contacts Instance of Contacts, that contains person's contact information 
     * @throws IllegalArgumentException if any of arguments was null.
     * @see Student
     * @see Teacher
     * @see Headman
     */
    public Person(Name name, Origin origin, Contacts contacts) {
        if (name == null || origin == null || contacts == null) {
            throw new IllegalArgumentException(NULL_ARGUMENT_MESSAGE);
        }
        
        this.name = name;
        this.origin = origin;
        this.contacts = contacts;
    }

    /**
     * Getter of contacts
     * @return Returns clone of contacts.
     */
    public Contacts getContacts() {
        return (Contacts) contacts.clone();
    }

    /**
     * Getter of name
     * @return Returns clone of name.
     */
    public Name getName() {
        return (Name) name.clone();
    }

    /**
     * Getter of origin
     * @return Returns clone of origin.
     */
    public Origin getOrigin() {
        return (Origin) origin.clone();
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder();
        
        builder.append(name.toString());
        builder.append(origin.toString());
        builder.append(contacts.toString());
        
        return builder.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Person other = (Person) obj;
        if (this.name != other.name && (this.name == null || !this.name.equals(other.name))) {
            return false;
        }
        if (this.origin != other.origin && (this.origin == null || !this.origin.equals(other.origin))) {
            return false;
        }
        if (this.contacts != other.contacts && (this.contacts == null || !this.contacts.equals(other.contacts))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 43 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 43 * hash + (this.origin != null ? this.origin.hashCode() : 0);
        hash = 43 * hash + (this.contacts != null ? this.contacts.hashCode() : 0);
        return hash;
    }
    
}
